<@pp.dropOutputFile/>
<#-- iterate table list-->
<#list doc.tables as table>

<#-- generate package name -->
<#assign package = doc.groupid?replace(".", "/")> 
<#assign package = package + "/" + doc.artifactid?replace(".", "/")>
<#assign package = package + "/" + table.moduleid?replace(".", "/")>
<#assign fileName = table.name?cap_first>
<@pp.changeOutputFile name="/main/java/" + package + "/service/" + fileName + "ServiceImpl.java"/>
package ${package?replace("/", ".")}.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;
import ${doc.groupid}.common.Outcome;
import java.util.LinkedList;
import ${package?replace("/", ".")}.dao.${table.name?cap_first}Dao;
import ${package?replace("/", ".")}.domain.${fileName};

/**
 * Class ${fileName}ServiceImpl
 * ${fileName}Service interface implementation.
 * @author ${doc.author}
 * @version ${doc.version}, ${doc.date}
 */
public class ${fileName}ServiceImpl implements ${fileName}Service{
	private ${fileName}Dao ${fileName?uncap_first}Dao = null;
	private Log log = LogFactoryImpl.getLog(${fileName}ServiceImpl.class);
	
	public Outcome create(${fileName} newValue){
		Outcome res = null;
		if(${fileName?uncap_first}Dao != null){
			res = ${fileName?uncap_first}Dao.create(newValue);
		}else{
			res = new Outcome();
			res.setMsg("create.input");
		}
		return res;
	}

	public Integer create4Server(Outcome oc) {
		Integer res = null;
		if(null != oc){
			if(oc.success()){
				res = (Integer)oc.getData();
			}
		}
		
		return null != res ? res : -1;
	}

	public Outcome get(Integer id) {
		Outcome res = null;
		if(${fileName?uncap_first}Dao != null){
			res = ${fileName?uncap_first}Dao.get(id);
		}else{
			res = new Outcome();
			res.setMsg("inject.fail");
		}
		return res;
	}
	public ${fileName} get4Server(Outcome oc){
		${fileName} res = null;
		if(null != oc){
			if(oc.success()){
				List<${fileName}> objs = (List<${fileName}>)oc.getData();
				if(null != objs && objs.size() > 0){
					res = objs.get(0);
				}
			}
		}
		
		return res;
	}
	
	public Outcome size(Integer id) {
		Outcome res = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		if(${fileName?uncap_first}Dao != null){
			res = ${fileName?uncap_first}Dao.size(map);
		}else{
			res = new Outcome();
			res.setMsg("inject.fail");
		}
		return res;
	}
	public Integer size4Server(Outcome oc){
		Integer res = null;
		if(null != oc){
			if(oc.success()){
				res = (Integer)oc.getData();
			}
		}
		
		return null != res ? res : 0;
	}
	
	public Outcome getAll(){
		return getPage(1, 10000, null);
	}
	public List<${fileName}> getAll4Server(Outcome oc){
		List<${fileName}> res = null;
		if(null != oc){
			if(oc.success()){
				res = (List<${fileName}>)oc.getData();
			}
		}
		
		return res != null ? res : new ArrayList<${fileName}>();
	}
	
	public Outcome getPage(Integer page, Integer rows, Integer id){
		Outcome res = null;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("pageNumber", page);
		map.put("pageSize", rows);
		map.put("id", id);
		if(${fileName?uncap_first}Dao != null){
			res = ${fileName?uncap_first}Dao.getPage(map);
		}else{
			res = new Outcome();
			res.setMsg("inject.fail");
		}
		return res;
	}
	public List<${fileName}> getPage4Server(Outcome oc){
		List<${fileName}> res = null;
		if(null != oc){
			if(oc.success()){
				res = (List<${fileName}>)oc.getData();
			}
		}
		
		return res != null ? res : new ArrayList<${fileName}>();
	}

	public Outcome update(${fileName} newValue){
		Outcome res = null;
		if(${fileName?uncap_first}Dao != null){
			res = ${fileName?uncap_first}Dao.update(newValue);
		}else{
			res = new Outcome();
			res.setMsg("inject.fail");
		}
		return res;
	}
	public Integer update4Server(Outcome oc){
		Integer res = null;
		if(null != oc){
			if(oc.success()){
				res = (Integer)oc.getData();
			}
		}
		
		return null != res ? res : 0;
	}
	
	public Outcome delete(Integer id){
		Outcome res = null;
		if(${fileName?uncap_first}Dao != null && null != id){
			List<Integer> ids = new ArrayList<Integer>();
			ids.add(id);
			res = ${fileName?uncap_first}Dao.deleteItems(ids);
		}else{
			res = new Outcome();
			res.setMsg("inject.fail");
		}
		return res;
	}
	public Integer delete4Server(Outcome oc){
		Integer res = null;
		if(null != oc){
			if(oc.success()){
				res = (Integer)oc.getData();
			}
		}
		
		return null != res ? res : 0;
	}

	public Outcome deleteItems(List<Integer> ids){
		Outcome res = null;
		if(${fileName?uncap_first}Dao != null){
			res = ${fileName?uncap_first}Dao.deleteItems(ids);
		}else{
			res = new Outcome();
			res.setMsg("inject.fail");
		}
		return res;
	}
	public Integer deleteItems4Server(Outcome oc){
		Integer res = null;
		if(null != oc){
			if(oc.success()){
				res = (Integer)oc.getData();
			}
		}
		
		return null != res ? res : 0;
	}
	
	public Outcome deleteAll(){
		Outcome res = null;
		if(${fileName?uncap_first}Dao != null){
			res = ${fileName?uncap_first}Dao.deleteAll();
		}
		return res;
	}
	public Integer deleteAll4Server(Outcome oc){
		Integer res = null;
		if(null != oc){
			if(oc.success()){
				res = (Integer)oc.getData();
			}
		}
		
		return null != res ? res : 0;
	}
	
	public void set${fileName}Dao(${fileName}Dao dao){
		${fileName?uncap_first}Dao = dao;
	}
}
</#list>